<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DoitPHP权限控件-DEMO</title>
<style type="text/css">
<!--
body {
	margin: 0px;
	padding: 0px;
	background-color: #FFF;
	text-align: center;
}
.total {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
	line-height: 25px;
	color: #000;
	height: auto;
	width: 750px;
	padding: 0px;
	text-align: left;
	margin-top: 30px;
	margin-right: auto;
	margin-bottom: 0px;
	margin-left: auto;
	border: 1px solid #AACCEE;
}
-->
</style></head>
<?php echo script::add('jquery'), script::add('thickbox'); ?>

<script type="text/javascript">
$(document).ready(function(){
	$('#add_new_option').click(function(){
	<?php if($mode == 1){ ?>
		var option_name = $('#option_name_box').val();
		if(option_name == ''){alert('acl option name 不能为空!'); $('#option_name_box').focus();return false;}else{$.post('<?php echo $this->create_url('index/ajax_insert_acl_option'); ?>', {option:option_name}, function(data){
			switch(data){
				case '101':
					alert('操作成功!');
					$('#option_name_box').val('');
					location.reload();
					break;
				case '100':
					alert('操作失败!请重新操作');								
					break;
				case '103':
					alert('所要添加的option name 已经存在!');
					$('#option_name_box').val('');					
					break;
			}
		});}
    <?php } else  if($mode == 2) { ?>
		var option_name = $('#option_name_box').val();
		var role_description = $('#role_description_box').val();
		if(option_name == ''){alert('acl role name 不能为空!'); $('#option_name_box').focus();return false;}else{$.post('<?php echo $this->create_url('index/ajax_insert_acl_role'); ?>', {role_name:option_name, description:role_description}, function(data){switch(data){case '101':$('#option_name_box').val('');$('#role_description_box').val('');alert('添加成功!');location.reload();break;case '100':alert('操作失败,请重新操作');break; case '103':alert('所要添加的角色已存在!');break;}});}
	<?php } else if($mode == 3) {?>
		var option_name = $('#option_name_box').val();
		var role_id = $('#role_box').val();
		if(option_name==''){alert('用户名不能为空!'); $('#option_name_box').focus();return false;}else{$.post('<?php echo $this->create_url('index/ajax_insert_user'); ?>', {role_id:role_id, user_name:option_name}, function(data){if(data==101){option_name = $('#option_name_box').val('');alert('添加成功!');location.reload();}else{alert('添加用户失败!请重新操作');}});}
	<?php } ?>
	});						   
});
function delete_acl_option(id) {
	if(confirm('你确认要进行删除操作？')){
		$.post('<?php echo $this->create_url('index/ajax_delete_acl_option'); ?>', {auth_option_id:id}, function(data){if(data==101){alert('操作成功!'); location.reload();}else{alert('操作失败,请重新操作');}});
	}else{
		return false;
	}
}
function edit_acl_option(id){
	var option_name = $('#acl_option_box').val();
	if(option_name == ''){
		alert('option name不能为空!');
		$('#acl_option_box').focus();
		return false;
	}
	$.post('<?php echo $this->create_url('index/ajax_handle_edit_acl_option'); ?>', {id:id, option_name:option_name}, function(data){
		switch(data){
			case '101':
				alert('操作成功!');
				location.reload();
				break;
			case '100':
				alert('操作失败!请重新操作');
				break;
			case '103':
				alert('对不起,'+option_name+'已存在！');
				break;
		}
	});
}
function delete_role(id){
	if(confirm('你确认要删除？')){
		$.post('<?php echo $this->create_url('index/ajax_delete_acl_role'); ?>', {id:id}, function(data){if(data==101){alert('操作成功!'); location.reload();}else{alert('操作失败!请重新操作');}});
	}else{
		return false;
	}
}
function edit_role_name(id){
	var role_name = $('#role_name_box').val();
	var role_description = $('#role_des_box').val();
	if(role_name==''){alert('角色名不能为空!');$('#role_name_box').focus();return false;}else{$.post('<?php echo $this->create_url('index/ajax_handle_edit_role'); ?>', {id:id, role_name:role_name, role_description:role_description}, function(data){switch(data){case'101':alert('编辑成功!'); location.reload();break;case'100':alert('操作失败!请重新操作');break;case'103':alert(role_name+'已经存在!');break;}});}
}
function delete_user(id){
	if(confirm('你确认要删除？')){$.post('<?php echo $this->create_url('index/ajax_delete_user'); ?>', {user_id:id}, function(data){if(data==101){alert('删除成功！');location.reload();}else{alert('删除失败！请重新操作');}});}else{return false;}
}
function edit_user_name(id){
	var user_name = $('#user_name_box').val();
	var role_id = $('#role_id_box').val();
	if(user_name==''){alert('用户名不能为空!');$('#user_name_box').focus();return false;}else{$.post('<?php echo $this->create_url('index/ajax_handle_edit_user'); ?>', {user_id:id, user_name:user_name, role_id:role_id}, function(data){switch(data){case'101':alert('操作成功!');location.reload();break;case'103':alert(user_name+'已经存在!');break;}});};
}
</script>
<?php echo $pagelist_css; ?>
<body>
<div class="total">
<table width="750" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="60" align="center">DoitPHP权限控制(Demo版)</td>
  </tr>
  <tr>
    <td height="30"><table width="750" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="10" height="30" bgcolor="#D3DFEE">&nbsp;</td>
        <?php if($mode == 1){?>
        <td width="150" align="center" bgcolor="#FFFFFF">操作(option)管理</td>
        <?php } else {?>
        <td width="150" align="center" bgcolor="#D3DFEE"><a href="<?php echo $this->create_url('index/index', array('mode'=>1, 'page'=>$page), false); ?>">操作(option)管理</a></td>
        <?php } 
		if($mode == 2) {
		?>        
        <td width="150" align="center" bgcolor="#FFFFFF">角色（role）管理</td>
        <?php } else { ?>
        <td width="150" align="center" bgcolor="#D3DFEE"><a href="<?php echo $this->create_url('index/index', array('mode'=>2, 'page'=>$page), false); ?>">角色（role）管理</a></td>
        <?php } 
		if($mode == 3) {
		?>
        <td width="150" align="center" bgcolor="#FFFFFF">用户(user)管理</td>
        <?php } else { ?>        
        <td width="150" align="center" bgcolor="#D3DFEE"><a href="<?php echo $this->create_url('index/index', array('mode'=>3, 'page'=>$page), false); ?>">用户(user)管理</a></td>
        <?php } ?>
        <td width="290" bgcolor="#D3DFEE">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="360" align="left" valign="top"><table width="750" border="0" cellspacing="0" cellpadding="0">
    	<tr>
        <td height="15"></td>
      </tr>
      <tr>
        <td height="40">&nbsp;&nbsp;&nbsp;<?php if ($mode == 2) {echo '角色:&nbsp;';}?><input type="text" name="option_value" id="option_name_box" style="width:150px; height:18px; line-height:18px; border:solid 1px #999;"/>&nbsp;&nbsp;<?php if($mode == 2){echo '说明:&nbsp;<input type="text" name="role_description" id="role_description_box" style="width:150px; height:18px; line-height:18px; border:solid 1px #999;">&nbsp;&nbsp;'; } if($mode == 3){echo '角色&nbsp;', html::select($select_array, array('name'=>'role_box', 'id'=>'role_box')), '&nbsp;&nbsp;';}?><input name="submit_button" type="button" value="添加" id="add_new_option"/></td>
      </tr>
      <tr>
        <td height="300" align="left" valign="top"><table width="750" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="10" colspan="3"></td>
            </tr>
          <tr>
            <td width="10" height="280">&nbsp;</td>            
            <td align="left" valign="top">
            <?php if($mode == 1){?> 
            <table width="730" border="0" cellspacing="1" cellpadding="0" style="background:#DEDEDE;">
              <tr>
                <td width="25" height="25" bgcolor="#FFFFFF">&nbsp;</td>
                <td align="center" bgcolor="#FFFFFF">Option</td>
                <td colspan="2" align="center" bgcolor="#FFFFFF">操作</td>
              </tr>
              <?php foreach((array)$list_data as $key=>$lines) { ?>
              <tr>
                <td height="25" align="center" bgcolor="#FFFFFF"><?php echo $key + 1; ?>.</td>
                <td align="left" bgcolor="#FFFFFF">&nbsp;<?php echo $lines['auth_option_name']; ?></td>
                <td width="70" align="center" bgcolor="#FFFFFF"><a href="<?php echo $this->create_url('index/ajax_edit_acl_option'); ?>/?height=120&width=420&id=<?php echo $lines['auth_option_id']; ?>" class="thickbox" title="编辑acl option">编辑</a></td>
                <td width="70" align="center" bgcolor="#FFFFFF"><a href="javascript:void(0);" onclick="delete_acl_option('<?php echo $lines['auth_option_id']; ?>')">删除</a></td>                
              </tr>
              <?php } ?>
            </table>
            <?php } else if($mode == 2) { ?>
            <table width="730" border="0" cellspacing="1" cellpadding="0" style="background:#DEDEDE;">
              <tr>
                <td width="25" height="25" bgcolor="#FFFFFF">&nbsp;</td>
                <td width="150" align="center" bgcolor="#FFFFFF">角色</td>
                <td align="center" bgcolor="#FFFFFF">说明</td>
                <td colspan="3" align="center" bgcolor="#FFFFFF">操作</td>
              </tr>
              <?php foreach((array)$list_data as $key=>$lines) {?>
              <tr>
                <td height="25" align="center" bgcolor="#FFFFFF"><?php echo $key + 1; ?>.</td>
                <td width="150" align="left" bgcolor="#FFFFFF">&nbsp;<?php echo $lines['role_name']; ?></td>
                <td align="left" bgcolor="#FFFFFF"><?php echo $lines['role_description']; ?></td>
                <td width="70" align="center" bgcolor="#FFFFFF"><a href="<?php echo $this->create_url('index/ajax_edit_acl_role'); ?>/?height=150&width=350&id=<?php echo  $lines['role_id']; ?>" class="thickbox" title="编辑角色">编辑</a></td>
                <td width="70" align="center" bgcolor="#FFFFFF"><a href="javascript:void(0);" onclick="delete_role(<?php echo $lines['role_id']; ?>)">删除</a></td>
                <td width="60" align="center" bgcolor="#FFFFFF"><a href="<?php echo $this->create_url('index/config_role', array('id'=>$lines['role_id']), false); ?>" target="_self">设置</a></td>                
              </tr>
              <?php } ?>
            </table>
            <?php } else if($mode == 3) {?>
             <table width="730" border="0" cellspacing="1" cellpadding="0" style="background:#DEDEDE;">
              <tr>
                <td width="25" height="25" bgcolor="#FFFFFF">&nbsp;</td>
                <td align="center" bgcolor="#FFFFFF">用户名</td>
                <td width="150" align="center" bgcolor="#FFFFFF">角色</td>
                <td colspan="3" align="center" bgcolor="#FFFFFF">操作</td>
              </tr>
              <?php foreach((array)$list_data as $key=>$lines) {?>
              <tr>
                <td height="25" align="center" bgcolor="#FFFFFF"><?php echo $key + 1; ?>.</td>
                <td align="left" bgcolor="#FFFFFF">&nbsp;<?php echo $lines['name']; ?></td>
                <td align="center" bgcolor="#FFFFFF"><?php echo $lines['role']; ?></td>
                <td width="70" align="center" bgcolor="#FFFFFF"><a href="<?php echo $this->create_url('index/ajax_edit_user') . '/?width=350&height=150&id=' . $lines['id']; ?>" class="thickbox" title="编辑用户">编辑</a></td>
                <td width="70" align="center" bgcolor="#FFFFFF"><a href="javascript:void(0);" onclick="delete_user(<?php echo $lines['id']; ?>)">删除</a></td>
                <td width="60" align="center" bgcolor="#FFFFFF"><a href="<?php echo $this->create_url('index/config_user', array('id'=>$lines['id']), false); ?>">查看</a></td>
              </tr> 
              <?php } ?>             
            </table>
            <?php } ?>
            </td>
            <td width="10">&nbsp;</td>
          </tr>
          <tr>
            <td height="10" colspan="3"></td>
            </tr>
        </table></td>
      </tr>
      <tr>
        <td height="30"><?php echo $pagelist_html; ?></td>
      </tr>      
    </table></td>
  </tr>
</table>
</div>
</body>
</html>